package com.springdemo.springaware;


import com.springdemo.annotation.Log;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Service;

import java.io.IOException;

@Service
public class AwareService implements BeanNameAware, ResourceLoaderAware {

  private String beanName;
  private ResourceLoader resourceLoader;

  @Override
  public void setBeanName(String s) {
    this.beanName = s;
  }

  @Override
  public void setResourceLoader(ResourceLoader resourceLoader) {
    this.resourceLoader = resourceLoader;
  }

@Log(type = Log.LOG_TYPE.ADD,desc = "增加参数")
  public String outPutResult(String str ,Integer i) {
    System.out.println("beanName:" + beanName);
    Resource resource = resourceLoader.getResource("classpath:test.txt");
    try {
      String s = IOUtils.toString(resource.getInputStream());
      System.out.println("resource读到的内容是" + s);
    } catch (IOException e) {
      e.printStackTrace();
    }
    System.out.println("str:"+str+",i:"+i);
    return "返回值";
  }

}